package com.pro.xwt.rest.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pro.xwt.common.model.BEmployee;
import com.pro.xwt.common.model.DSharing;
import com.pro.xwt.common.service.DSharingService;
import com.pro.xwt.common.utils.Common;
import com.pro.xwt.common.utils.DateFormatter;
import com.pro.xwt.rest.ResponseResult;

@Controller
@RequestMapping("/share")
public class ShareController {
	@Autowired
	DSharingService dSharingService;

	/**
	 * 新建分享接口
	 * 
	 * @return
	 */
	@RequestMapping(method = { RequestMethod.POST }, value = "")
	@ResponseBody
	public ResponseResult setFolder(@RequestBody DSharing dSharing, HttpServletRequest request) {
		Integer flag = 0;
		BEmployee user = (BEmployee) request.getAttribute("user");
		dSharing.setId(Common.generateUUID());
		dSharing.setDeleteState("0");
		dSharing.setShareEmpId(user.getId());
		dSharing.setShareBeginTime(new Date());
		dSharing.setShareEndTime(DateFormatter.getNextSeveralDay(new Date(),2));
		flag = dSharingService.insert(dSharing);
		if (flag > 0) {
			return ResponseResult.success("新建分享接口成功", dSharing);
		}
		return ResponseResult.fail("新建分享接口失败", flag);
	}

}
